import {StoreCreator} from "@/types/utils";
import {SpinnerState} from "@/store/types";


const initialState = {
    showSpinner: false,
    loadingDuration: 2000, // 加载持续时间
    loadingText: '加载中...', // 加载提示文字
}
export const createSpinnerSlice: StoreCreator<SpinnerState> = (set, get) => ({
    ...initialState,

    showLoading(content?: string) {
        set(state => {
            state.showSpinner = true;
            state.loadingText = content ?? state.loadingText;
        });
    },
    hideLoading() {
        set(state => {
            state.showSpinner = false;
        })
    },
    resetSpinner() {
        set(initialState);
    }
})